<?php

namespace App\Repositories\Criteria;

use Prettus\Repository\Contracts\CriteriaInterface;
use Prettus\Repository\Contracts\RepositoryInterface;

/**
 * Class MchNoCriteria
 * @package namespace App\Repositories\Criteria;
 */
class MchNoCriteria implements CriteriaInterface
{
    protected $mch_no;
    protected $field;

    public function __construct($mch_no='', $field='merchant_no')
    {
        $this->field = $field;
        $this->mch_no = $mch_no;
    }

    /**
     * Apply criteria in query repository
     *
     * @param                     $model
     * @param RepositoryInterface $repository
     *
     * @return mixed
     */
    public function apply($model, RepositoryInterface $repository)
    {
        if (strlen($this->mch_no) != 0) {
            return $model->where($this->field, 'like', '%'.$this->mch_no.'%');
        }
        return $model;
    }
}
